import axios, { type AxiosResponse, type InternalAxiosRequestConfig,type AxiosRequestConfig } from 'axios'
const {VITE_BASE_URL,VITE_BASE_API} = import.meta.env
//请求封装
export const http = axios.create({
    baseURL:VITE_BASE_URL+VITE_BASE_API,
    headers:{
        'Content-Type':'application/json'
    },
    withCredentials:true,
})
//请求拦截
http.interceptors.request.use((config:InternalAxiosRequestConfig)=>{
    return config
})
//响应拦截
http.interceptors.response.use(res=>{
    const {data} = res
    return data
})
//封装get
export function request<T,D>(url:string,config:AxiosRequestConfig<D>={}){
   return http.get<T>(url,{
        ...config
    })
}
//封装post
export function requestPost<T,D>(url:string,config:AxiosRequestConfig<D>={}){
   return http.post<T>(url,{
        ...config
    })
}


